package com.network;

import com.xingjibase.params.*;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;

/**
 * <pre>
 *     author : Roacher
 *     time   : 2017/12/14
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public enum ApiFactory {
    INSTANCE;

    private final ServiceToRequest mNomalService;

    ApiFactory() {
        mNomalService = RetrofitClient.INSTANCE.getRetrofit().create(ServiceToRequest.class);
    }

    public ServiceToRequest getNomalService() {
        return mNomalService;
    }

    /**
     * 验证用户是否存在
     */
    public void rxjava_verifyn(Observer<ResponseBody> mSubscriber, PartForVerify verifyParams) {
        execute(getNomalService().verifyn(verifyParams), mSubscriber);
    }

    /**
     * 登录
     *
     * @param mSubscriber
     */
    public void rxjava_login(Observer<ResponseBody> mSubscriber, PartForLogin loginParams) {
        execute(getNomalService().login(loginParams), mSubscriber);
    }

    /**
     * 刷新登录状态
     */
    public void rxjava_refresh(String sessionId, Observer<ResponseBody> mSubscriber) {
        execute(getNomalService().refreshStatus(sessionId), mSubscriber);
    }

    /**
     * 获取地锁列表
     *
     * @param mSubscriber
     */
    public void rxjava_lockList(String sessionId, Observer<ResponseBody> mSubscriber) {
        execute(getNomalService().lockList(sessionId), mSubscriber);
    }

    /**
     * 设置地锁名称
     *
     * @param mSubscriber
     */
    public void rxjava_lockSet(PartForSetLock mParams, Observer<ResponseBody> mSubscriber) {
        execute(getNomalService().lockSet(mParams), mSubscriber);
    }

    /**
     * 获取用户基本信息
     *
     * @param mSubscriber
     */
    public void rxjava_userInfo(String sessionId, Observer<ResponseBody> mSubscriber) {
        execute(getNomalService().userInfo(sessionId), mSubscriber);
    }

    /**
     * 设置为默认地锁
     *
     * @param mSubscriber
     */
    public void rxjava_defaultLock(DefaultLockParams mParams, Observer<ResponseBody> mSubscriber) {
        execute(getNomalService().defaultLock(mParams), mSubscriber);
    }

    /**
     * 删除地锁
     *
     * @param mSubscriber
     */
    public void rxjava_deleteLock(DefaultLockParams mParams, Observer<ResponseBody> mSubscriber) {
        execute(getNomalService().deleteLock(mParams), mSubscriber);
    }

    /**
     * 添加地锁
     *
     * @param mSubscriber
     */
    public void rxjava_addLock(LockAddParams params, Observer<ResponseBody> mSubscriber) {
        execute(getNomalService().addLock(params), mSubscriber);
    }

    /**
     * 查询地锁数据
     *
     * @param mSubscriber
     */
    public void rxjava_checkId(Observer<ResponseBody> mSubscriber, PartForCheckId loginParams) {
        execute(getNomalService().checkId(loginParams), mSubscriber);
    }


    /**
     * 验证码
     *
     * @param mSubscriber
     */
    public void rxjava_code(Observer<ResponseBody> mSubscriber, String codeStr) {
        execute(getNomalService().code(codeStr), mSubscriber);
    }

    /**
     * 查询二级医师职称
     *
     * @param mSubscriber
     */
    public void rxjava_department_level(Observer<ResponseBody> mSubscriber) {
        execute(getNomalService().departmentLevel(), mSubscriber);
    }

    public void execute(Observable<ResponseBody> reponse_observable, Observer<ResponseBody> mSubscriber) {
        reponse_observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(mSubscriber);
    }
}
